package org.anupta.game.server.game.packet.account.character.channel;

import org.anupta.game.main.Main;
import org.anupta.game.server.game.client.GameClient;
import org.anupta.game.server.game.packet.GamePacket;

public class ChangeChannel extends GamePacket {
	private char action = ' ';
	private String channel = null;

	public ChangeChannel(GameClient client, String message) {
		super(client, message);
		unpack();
		pack();
		doPacket();
	}

	@Override
	public void unpack() {
		action = packetIn.charAt(3);
		channel = packetIn.substring(3);
	}

	@Override
	public void pack() {
		packetOut.append("cC").append(action).append(channel);
	}

	@Override
	public void doPacket() {
		switch(action){
		case '+':
			client.getPlayer().setChannels(client.getPlayer().getChannels() + channel);
			break;
		case '-':
			client.getPlayer().setChannels(client.getPlayer().getChannels().replace(channel, ""));
			break;
		}
		client.send(packetOut.toString());
		Main.out.println(new StringBuilder("Channel change of player : ").append(client.getPlayer().getGuid()).toString());
	}
}
